package com.thinqq.web.server;

import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;


public class DataStoreService {
	PersistenceManager manager;
	public DataStoreService(){
		manager = PersistentManagerFactoryForAppEngine.get().getPersistenceManager();
	}

	/**
	 * Begin a new transaction.
	 *
	 * @return the transaction
	 */
	public Transaction begin() {
		final Transaction tx = manager.currentTransaction();
		tx.begin();
		return tx;
	}

	/**
	 * Close the connection to the data store. Clients are expected to guarantee
	 * that close will be called. This will also rollback any active
	 * transaction.
	 */
	public void close() {
		final Transaction tx = manager.currentTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
		manager.close();
	}
	
	/**
	 * Store Lead info
	 * @param lead
	 */
	public void storeLead(Lead lead){
		Transaction txn = begin();
		manager.makePersistent(lead);
		txn.commit();
	}

}
